home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#23 (Aug 87)
/
find traps source
/
IsTrap.c
Wrap
C/C++ Source or Header
|
1987-06-22
|
3KB
|
127 lines
/* IsTrap.c: Detect trap availability
Written by Joel West in MPW C, June 1987
Compiled as an MPW tool (shell command); usage:
IsTrap A010 A060 print information on traps $A010 and $A060
IsTrap A800 -A830 information on all traps from $A800 to $A830
There is one option letter (which like UNIX and unlike MPW, must come first):
-p show detailed "progress" information
Status values returned:
0 ok
1 syntax error
2 trap not implemented
*/
#include <Memory.h> /* for THz heap zone pointer */
#include <OSUtils.h> /* for GetTrapAddress() */
#include <stdio.h>
#define UNDEFTRAP 0x9F
#define GETLONG(addr) *( (long *) addr) /* grab a low-memory global value */
#define ROMBase GETLONG(0x2AEL)
typedef short Half;
typedef unsigned short UHalf; /* traps are Axxx, normally negative numbers */
typedef unsigned long Addr; /* for unsigned address comparisons */
int strspn(),strlen();
long MyGetTrapAddr();
void syntaxerr();
THz syshz;
#define INSYSHEAP(a) (a > (long) syshz && a < (long) syshz->bkLim)
main(argc,argv)
int argc;
char **argv;
{ int argno,len,status;
Boolean range,verbose=0;
Addr trapword, trapaddr, unimpaddr, rombegin;
UHalf oldword=0,t;
char *p;
unimpaddr = GetTrapAddress(UNDEFTRAP);
rombegin = ROMBase;
syshz = SystemZone();
argno = 1; /* parameter number */
if (argno < argc && ! strcmp(argv[argno], "-p")) /* -v for you UNIX types */
{ verbose++;
argno++;
}
if (argno >= argc)
syntaxerr(argv);
if (verbose)
{ printf("ROM @ %X\n", rombegin);
printf("System heap from %X to %X\n", syshz, syshz->bkLim);
}
status = 0;
for (; argno<argc; argno++)
{ range = 0;
p = argv[argno];
if (*p == '-')
{ p++;
range++;
}
len = strlen(p);
if (len && len == strspn(p, "0123456789ABCDEF"))
{ sscanf(p,"%lx",&trapword);
if (range)
t = oldword+1;
else
t = trapword;
for (; t<=trapword; t++)
{ trapaddr = MyGetTrapAddr(t);
printf("Trap %lX is ", t);
if (verbose)
printf("%lX, ", trapaddr);
if (trapaddr == unimpaddr)
{ printf("undefined\n");
status = 2; /* indicate result to shell */
}
else
if (trapaddr >= rombegin)
printf("in ROM\n");
else if (INSYSHEAP(trapaddr))
printf("patched\n");
else /* in application heap? */
printf("overridden\n");
}
oldword = trapword;
}
else
syntaxerr(argv);
}
exit(status);
}
void syntaxerr(argv)
char **argv;
{ fprintf(stderr, "# %s - invalid syntax.\n", argv[0]);
fprintf(stderr, "# %s - usage: %s [-p] trap…\n", argv[0], argv[0]);
exit(1);
}
/* Find the trap address for a given trap word.
The 128K ROM provides NGetTrapAddress (a glue routine), which
distinguishes between OS and Toolbox traps. This eventually
uses the same trap number as GetTrapAddress, so it seems
to work fine on the 64K ROM.
*/
long MyGetTrapAddr(trapword)
UHalf trapword;
{ UHalf trapnum;
TrapType typ;
if ((long)trapword < 0x0000A800L)
{ typ = OSTrap;
trapnum = trapword & 0xFF;
}
else
{ typ = ToolTrap;
trapnum = trapword & 0x3FF;
}
return NGetTrapAddress(trapnum, typ);
}